package com.qf.java2201.web.bk;

import com.alibaba.fastjson.JSON;
import com.qf.java2201.common.R;
import com.qf.java2201.pojo.HUserinfo;
import com.qf.java2201.service.UserInfoService;
import com.qf.java2201.service.impl.UserInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @date 2022/4/1
 * @desc
 */
@WebServlet("/doctorsPageData")
public class DoctorsListServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setContentType("application/json; charset=UTF-8");


        // 接受模糊查询的数据
        String drealname = req.getParameter("drealname");  // 姓名
        String ks = req.getParameter("ks");  // 科室
        String dphone = req.getParameter("dphone");  // 电话

        String page = req.getParameter("page");  // 页码
        String limit = req.getParameter("limit"); // 每页显示记录数

        HUserinfo hUserinfo = new HUserinfo();


        // 把接受的 字符串类型的  页码page   和 每页显示的记录数  limit 转为 int 类型
        int pageNum = Integer.parseInt(page);
        int pageSize = Integer.parseInt(limit);

        UserInfoService userInfoService = new UserInfoServiceImpl();
        R<List<HUserinfo>> r = userInfoService.getPageData(pageNum,pageSize,hUserinfo);

        //fastjson 把 java 对象 转为 json 串
        String s = JSON.toJSONString(r);
        
        // 可以使用下面的工具类
        //String s = FastJsonUtils.convertObjectToJSON(r);
        resp.getWriter().println(s);


    }
}
